/*
 * @Author: your name
 * @Date: 2020-06-09 16:51:11
 * @LastEditTime: 2020-06-28 17:44:28
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \jujij_shop\lib\services\user.dart
 */
import 'package:shared_preferences/shared_preferences.dart';
import '../utils/dio_util.dart';

class User {
  //获取用户信息
  static getUserInfo() async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    String token = sp.getString('token');
    if (token != null) {
      DioUtil dioUtil = DioUtil();
      var userinfo = await dioUtil.get('/api/mall/user/userinfo.service');
      return userinfo;
    } else {
      return {'success': false};
    }
  }
  //判断是否登录
  static Future<bool> hasLogin() async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    String gettoken = sp.getString('token');
    if (gettoken !=null) {
      return true;
    }
    return false;
  }

  static loginOut() async {
    SharedPreferences sp = await SharedPreferences.getInstance();
    sp.remove('token');
  }
}
